package com.sdry.service.impl.hpf;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sdry.mapper.hpf.ApprovalRecordMapper;
import com.sdry.mapper.hpf.PickApplyMapper;
import com.sdry.model.hpf.AndroidApprovalRecord;
import com.sdry.model.hpf.ApprovalRecord;
import com.sdry.model.hpf.PickApply;
import com.sdry.service.hpf.ApprovalRecordService;

/**
 * @ClassName: ApprovalRecordService 
 * @Description:审批记录Service实现
 * @Author hpf
 * @Date 2018年12月10日 上午10:31:29 
 * @version 1.0
 */
@Service
public class ApprovalRecordServiceImpl implements ApprovalRecordService {

	@Resource
	private ApprovalRecordMapper approvalRecordMapper;
	@Resource
	private PickApplyMapper pickApplyMapper;
	
	/**
	 * 分页查询待办
	 * @param map
	 * @return
	 */
	public List<ApprovalRecord> listPageApprovalRecord(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return approvalRecordMapper.listPageApprovalRecord(map);
	}
	
	/**
	 * 分页查询已办
	 * @param map
	 * @return
	 */
	public List<ApprovalRecord> listPageApprovalComplete(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return approvalRecordMapper.listPageApprovalComplete(map);
	}

	/**
	 * 总数待办
	 * @param pickID
	 * @return
	 */
	public Integer countApprovalRecord(Long pickID) {
		// TODO Auto-generated method stub
		return approvalRecordMapper.countApprovalRecord(pickID);
	}
	
	/**
	 * 总数已办
	 * @param pickID
	 * @return
	 */
	public Integer countApprovalComplete(Long pickID) {
		// TODO Auto-generated method stub
		return approvalRecordMapper.countApprovalComplete(pickID);
	}

	/**
	 * 查询全部
	 * @param pickID
	 * @return
	 */
	public List<ApprovalRecord> listAllApprovalRecord(Long pickID) {
		// TODO Auto-generated method stub
		return approvalRecordMapper.listAllApprovalRecord(pickID);
	}

	/**
	 * 新增
	 * @param approvalRecord
	 * @return
	 */
	public Integer insertApprovalRecord(ApprovalRecord approvalRecord) {
		// TODO Auto-generated method stub
		return approvalRecordMapper.insertApprovalRecord(approvalRecord);
	}

	/**
	 * 删除
	 * @param arID
	 * @return
	 */
	public Integer deleteApprovalRecord(Long arID) {
		// TODO Auto-generated method stub
		return approvalRecordMapper.deleteApprovalRecord(arID);
	}

	@Override
	public List<AndroidApprovalRecord> listAllAndroidApprovalRecord(Long approverID) {
		// TODO Auto-generated method stub
		SimpleDateFormat formatDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
		List<AndroidApprovalRecord> androidApprovalRecordList = new ArrayList<>();
		List<ApprovalRecord> approvalRecordList = approvalRecordMapper.listAllAndroidApprovalRecord(approverID);
		for (int i = 0; i < approvalRecordList.size(); i++) {
			ApprovalRecord approvalRecord = approvalRecordList.get(i);
			AndroidApprovalRecord androidApprovalRecord = new AndroidApprovalRecord();
			androidApprovalRecord.setArID(approvalRecord.getArID()+"");
			androidApprovalRecord.setPickID(approvalRecord.getPickID()+"");
			androidApprovalRecord.setApprovalType(approvalRecord.getApprovalType());
			androidApprovalRecord.setSubmitterID(approvalRecord.getSubmitterID()+"");
			androidApprovalRecord.setApproverID(approvalRecord.getApproverID()+"");
			androidApprovalRecord.setStatus(approvalRecord.getStatus()+"");
			androidApprovalRecord.setRemark(approvalRecord.getRemark());
			androidApprovalRecord.setSubmitterName(approvalRecord.getSubmitterName());
			androidApprovalRecord.setApproverName(approvalRecord.getApproverName());
			androidApprovalRecord.setsSubmitDate(formatDateTime.format(approvalRecord.getSubmitDate()));
			PickApply pickApply = pickApplyMapper.findPickApplyByID(approvalRecord.getPickID());
			androidApprovalRecord.setPickNum(pickApply.getPickNum());
			androidApprovalRecord.setsPickDate(formatDate.format(pickApply.getPickDate()));
			androidApprovalRecord.setPickDeptName(pickApply.getPickDeptName());
			androidApprovalRecord.setPickPersonName(pickApply.getPickPersonName());
			androidApprovalRecord.setsDemandDate(formatDate.format(pickApply.getDemandDate()));
			androidApprovalRecordList.add(androidApprovalRecord);
		}
		return androidApprovalRecordList;
	}

}
